import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { fileURLToPath, URL } from 'node:url'

// 加载自动导入的插件
import AutoImport from 'unplugin-auto-import/vite'

// 兼容nodejs require方法
import commonjs from 'vite-plugin-commonjs'

// 加载自动生成路由插件
import Pages from 'vite-plugin-pages'

// 加载scope-css插件
import { reactScopedCssPlugin } from 'rollup-plugin-react-scoped-css'

// https://vite.dev/config/
export default defineConfig({
    server: {
        proxy: {
            '/hotel': {
                // target: "http://www.fast.com/hotel",
                target: "https://gxxfast.luckyxixi.cn/hotel",
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/hotel/, '')
            }
        }
    },
    plugins: [
        react(),
        commonjs(),
        reactScopedCssPlugin(),
        AutoImport({
            imports: ['react', 'react-router-dom']
        }),
        Pages({
            dirs: 'src/views',
            exclude: ['**/components/*.tsx']
        })
    ],
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url)) 
        }
    }
})
